/**
 *   This file is part of JGroove.
 *
 *   JGroove is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU Lesser General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   JGroove is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *   GNU Lesser General Public License for more details.
 *
 *   You should have received a copy of the GNU Lesser General Public License
 *   along with JGroove. If not, see <http://www.gnu.org/licenses/>.
 **/

package jgroove.json;

import java.util.HashMap;
import java.net.MalformedURLException;
import java.io.IOException;

import jgroove.JGroove;

/**
 * Class that represents the basic Json post object to make the petition to a
 * Grooveshark's service, it is mainly used by callMethod and should not be
 * used out of there but if you want to complicate your life.
 * @author Aitor Ruano Miralles <0x077d@gmail.com>
 */
public class JsonPost {
    public final HashMap<String, String> header = new HashMap<String, String>();
    {
        header.put("client", JGroove.name);
        header.put("clientRevision", JGroove.version);
        header.put("uuid", JGroove.uuid);
    }
    public static final HashMap<String, String> country = new HashMap<String, String>();
    static {
        country.put("IPR", "1201");
        country.put("ID", "223");
        country.put("CC1", "0");
        country.put("CC2", "0");
        country.put("CC3", "0");
        country.put("CC4", "2147483648");
    }
    public HashMap<String, Object> parameters;
    public String method;
    public static final String privacy = "1";

    /**
     * Attach the parameters and the method to the JsonPost abstract class to
     * send it via http, it will also automatically get the session id if it
     * hasn't been done already
     * @param parameters Paramaters to post
     * @param method Method to call
     */
    public JsonPost(HashMap<String, Object> parameters, String method) throws IOException{
        this.parameters = parameters;
        this.method = method;

        if (JGroove.getCurrentSessionID().isEmpty()){
            this.header.put("session", JGroove.getSessionID());
        } else {
            this.header.put("session", JGroove.getCurrentSessionID());
        }
    }
}
